package com.ctgu.demo.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctgu.demo.dao.CakeMapper;
import com.ctgu.demo.entity.Cake;
import com.ctgu.demo.service.CakeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * @program:
 * @description:
 * @author: gh
 * @create: 2020-06-22 12:25
 **/
@Service
public class CakeServiceImpl extends ServiceImpl<CakeMapper, Cake> implements CakeService {
    @Autowired
    private CakeMapper cakeMapper;

    @Override
    public IPage<Cake> getAll(int page, int size) {
        QueryWrapper<Cake> wrapper =new QueryWrapper<Cake>();
        IPage<Cake> cakeIPage = cakeMapper.selectPage(new Page<>(page,size), wrapper);
        return cakeIPage;
    }
    @Override
    public IPage<Cake> selectCake(String name, int page, int size){
        QueryWrapper<Cake> cakeIPage = new QueryWrapper<>();
        cakeIPage.like("cake_id", name).or().like("cake_name", name).or().like("cake_maker", name);
        IPage<Cake> cakesIPage = cakeMapper.selectPage(new Page<>(page, size), cakeIPage);
        return cakesIPage;
    }
}
